/* $Id: AbstractAdminDTOEntry.java 137 2011-08-29 20:33:36Z altdotua@gmail.com $ */

package alt.djudge.frontend.shared.dto.admin;

import java.util.Vector;


public abstract class AbstractAdminDTOEntry implements AdminDTOEntry
{
	final String[] defaultActions = new String[] {
		"Copy",
		"Edit",
	};
	
	public String[] getActionNames()
	{
		Vector<String> strings = new Vector<String>();
		for (String string : defaultActions)
		{
			strings.add(string);
		}
		for (String string : getCustomActions())
		{
			strings.add(string);
		}
		return strings.toArray(new String[0]);
	}
	
	protected String[] getCustomActions()
	{
		return new String[0];
	}
	
	public abstract String getOwnFieldValue(int fieldIndex);
	
	public String getFieldValue(int fieldIndex)
	{
		if (fieldIndex >= 0)
			return getOwnFieldValue(fieldIndex);
		if (fieldIndex == -1)
			return "" + isActive();
		if (fieldIndex == -2)
			return "" + isVisible();
		if (fieldIndex == -3)
			return "" + isDeleted();
		return null;
	}
	
	@Override
	public String toString()
	{
		StringBuilder sb = new StringBuilder();
		sb.append("" + getClass().getName() + ":[");
		for (int i = 0; i < getFieldNames().length; i++)
		{
			if (i > 0)
				sb.append(", ");
			sb.append(getOwnFieldValue(i));
		}
		sb.append("]");
		return sb.toString();
	}
}
